*** final analysis for Guineales Solola DM paper
*** use baseline WDF data set and do files
**21 Jan 2022 Peter Rohloff

use "/Users/peter.rohloff/Desktop/WDF REAIM analysis/solola paper/ppreprepdatasolola2.dta", clear


drop if hba1c1 < 6.5 & anoscondiabetes >= 1

tab genero if studysite==1 & (hba1c1>=6.5 | (hba1c1 < 6.5 & anoscondiabetes < 1))

summarize edad if studysite==1 & hba1c1>=6.5


tab etnicidad if studysite==1 & hba1c1>=6.5

summarize anosdeeducacion if studysite==1 & hba1c1>=6.5
summarize anosdeeducacion if studysite==1 & hba1c1>=6.5, detail


summarize anoscondiabetes if studysite==1 & hba1c1>=6.5
summarize anoscondiabetes if studysite==1 & hba1c1>=6.5, detail

summarize hba1c1 if studysite==1 & hba1c1>=6.5


gen baselinediabetescontrol=.
replace baselinediabetescontrol=0 if hba1c1 >= 8
replace baselinediabetescontrol=1 if hba1c1 >=7 & hba1c1 < 8
replace baselinediabetescontrol=2 if hba1c1 < 7
replace baselinediabetescontrol=. if hba1c1 == .

tab baselinediabetescontrol if studysite==1 & hba1c1>=6.5


summarize sbp1 if studysite==1 & hba1c1>=6.5
summarize dbp1 if studysite==1 & hba1c1>=6.5
tab hypertensive1 if studysite==1 & hba1c1>=6.5

summarize imc1 if studysite==1 & hba1c1>=6.5

tab imccat1 if studysite==1 & hba1c1>=6.5


summarize hba1c1 hba1c2 if studysite==1 & hba1c1>=6.5
summarize sbp1 sbp2 if studysite==1 & hba1c1>=6.5
summarize dbp1 dbp2 if studysite==1 & hba1c1>=6.5
summarize imc1 imc2 if studysite==1 & hba1c1>=6.5

summarize DKQsum1 DKQsum2 if studysite==1 & hba1c1>=6.5
summarize DistressMean1 DistressMean2 if studysite==1 & hba1c1>=6.5

summarize FirstSC1 SecondSC1 if studysite==1 & hba1c1>=6.5, detail
summarize FirstSC3 SecondSC3 if studysite==1 & hba1c1>=6.5, detail
summarize FirstSC4 SecondSC4 if studysite==1 & hba1c1>=6.5, detail
summarize FirstSC6 SecondSC6 if studysite==1 & hba1c1>=6.5, detail

/// get ready for regression analysis, using only people > 6.5 baseline a1c (there were 5 with A1C < 6.5 who met inclusion criteria, only one participated - leave them out)

 drop if hba1c1 < 6.5
 
 
//create variable for baseline values to input into regression models 
//by unit_identifier (time_variable), sort: gen baseline_dep_var = dep_var[1]


//** NOTE ** IF RESHAPE TO WIDE IT WONT WORK**
//hba1c
by numerodepaciente_e_i (time), sort: gen baseline_hba1c = hba1c[1]

//sbp
by numerodepaciente_e_i (time), sort: gen baseline_sbp = sbp[1]
//dbp
by numerodepaciente_e_i (time), sort: gen baseline_dbp = dbp[1]
//imc
by numerodepaciente_e_i (time), sort: gen baseline_imc = imc[1]
//DKQsum
by numerodepaciente_e_i (time), sort: gen baseline_dkq = DKQsum[1]
//DistressMean
by numerodepaciente_e_i (time), sort: gen baseline_distress = DistressMean[1]
//firstSC
by numerodepaciente_e_i (time), sort: gen baseline_firstSC = firstSC[1]
//secondSC
by numerodepaciente_e_i (time), sort: gen baseline_secondSC = secondSC[1]
//thirdSC
by numerodepaciente_e_i (time), sort: gen baseline_thirdSC = thirdSC[1]
//fourthSC
by numerodepaciente_e_i (time), sort: gen baseline_fourthSC = fourthSC[1]
//fifthSC
by numerodepaciente_e_i (time), sort: gen baseline_fifthSC = fifthSC[1]
//sixthSC
by numerodepaciente_e_i (time), sort: gen baseline_sixthSC = sixthSC[1]

**** regressions

mixed hba1c i.time edad i.etnicidad i.genero anosdeeducacion anoscondiabetes i.dificultadpagando baseline_hba1c || numerodepaciente_e_i:

mixed hba1c i.time#i.covid edad i.etnicidad i.genero anosdeeducacion anoscondiabetes i.dificultadpagando baseline_hba1c || numerodepaciente_e_i:


mixed sbp i.time#i.covid edad i.etnicidad i.genero anosdeeducacion anoscondiabetes i.dificultadpagando baseline_sbp || numerodepaciente_e_i:



mixed dbp i.time#i.covid edad i.etnicidad i.genero anosdeeducacion anoscondiabetes i.dificultadpagando baseline_dbp || numerodepaciente_e_i:



mixed imc i.time#i.covid edad i.etnicidad i.genero anosdeeducacion anoscondiabetes i.dificultadpagando baseline_imc || numerodepaciente_e_i:


mixed DKQsum i.time#i.covid edad i.etnicidad i.genero anosdeeducacion anoscondiabetes i.dificultadpagando baseline_dkq  || numerodepaciente_e_i: 


mixed DistressMean i.time#i.covid edad i.etnicidad i.genero anosdeeducacion anoscondiabetes i.dificultadpagando baseline_distress || numerodepaciente_e_i: 


meologit firstSC i.time#i.covid edad i.etnicidad i.genero anosdeeducacion anoscondiabetes i.dificultadpagando baseline_firstSC || numerodepaciente_e_i: 



meologit thirdSC i.time#i.covid edad i.etnicidad i.genero anosdeeducacion anoscondiabetes i.dificultadpagando baseline_thirdSC || numerodepaciente_e_i: 




meologit fourthSC i.time#i.covid edad i.etnicidad i.genero anosdeeducacion anoscondiabetes i.dificultadpagando baseline_fourthSC || numerodepaciente_e_i: 



meologit sixthSC i.time#i.covid edad i.etnicidad i.genero anosdeeducacion anoscondiabetes i.dificultadpagando baseline_sixthSC || numerodepaciente_e_i: 


*** imputations

mdesc edad genero idiomaprerido anosdeeducacion educaciondiabetes dificultadpagando hba1c1 hba1c2 sbp1 dbp1 sbp2 dbp2 imc1 DKQsum1 DKQsum2 DistressMean1 DistressMean2 imc2 firstSC1 secondSC1 thirdSC1 fourthSC1 fifthSC1 sixthSC1 firstSC2 secondSC2 thirdSC2 fourthSC2 sixthSC2 fifthSC2

mi set wide

mi register imputed hba1c1  hba1c2 sbp2 dbp2 imc2 sbp1 dbp1 imc1 etnicidad edad anosdeeducacion anoscondiabetes dificultadpagando

mi register regular genero 

mi impute chained (regress) hba1c2 sbp2 dbp2 imc2 sbp1 dbp1 imc1 edad anosdeeducacion anoscondiabetes (logit) etnicidad (ologit) dificultadpagando = genero hba1c1, add(100) rseed(12345)


// clinical variables

mi reshape long hba1c sbp dbp imc imccat, i(numerodepaciente_e_i) j(time)



mi estimate: mixed hba1c i.time edad i.etnicidad i.genero anosdeeducacion anoscondiabetes i.dificultadpagando baseline_hba1c || numerodepaciente_e_i:


mi estimate: mixed sbp i.time edad i.etnicidad i.genero anosdeeducacion anoscondiabetes i.dificultadpagando baseline_sbp || numerodepaciente_e_i:


mi estimate: mixed dbp i.time edad i.etnicidad i.genero anosdeeducacion anoscondiabetes i.dificultadpagando baseline_dbp || numerodepaciente_e_i:


mi estimate: mixed imc i.time edad i.etnicidad i.genero anosdeeducacion anoscondiabetes i.dificultadpagando baseline_imc || numerodepaciente_e_i:


// psychometric variables


mi register imputed etnicidad edad anosdeeducacion anoscondiabetes dificultadpagando DKQsum1 DKQsum2 firstSC1 secondSC1 thirdSC1 fourthSC1 fifthSC1 sixthSC1 firstSC2 secondSC2 thirdSC2 fourthSC2 fifthSC2 sixthSC2 DistressMean1 DistressMean2 

mi register regular genero baseline_dkq baseline_distress baseline_firstSC baseline_secondSC baseline_thirdSC baseline_fourthSC baseline_fifthSC baseline_sixthSC


mi impute chained (regress) edad anosdeeducacion anoscondiabetes DKQsum1 DKQsum2 DistressMean2 DistressMean1 (logit) etnicidad  (ologit) firstSC1 thirdSC1 fourthSC1 sixthSC1 firstSC2 thirdSC2 fourthSC2 sixthSC2 dificultadpagando = genero, force augment add(100) rseed(12345)


mi reshape long hba1c sbp dbp imc DKQsum DistressMean firstSC thirdSC fourthSC sixthSC, i(numerodepaciente_e_i) j(time)


mi estimate, cmdok: mixed DKQsum i.time edad i.etnicidad i.genero anosdeeducacion anoscondiabetes i.dificultadpagando baseline_dkq || numerodepaciente_e_i:


mi estimate, cmdok: mixed DistressMean i.time edad i.etnicidad i.genero anosdeeducacion anoscondiabetes i.dificultadpagando baseline_distress || numerodepaciente_e_i:


mi estimate, cmdok: meologit firstSC i.time edad i.etnicidad i.genero anosdeeducacion anoscondiabetes i.dificultadpagando baseline_firstSC || numerodepaciente_e_i:


mi estimate, cmdok: meologit thirdSC i.time edad i.etnicidad i.genero anosdeeducacion anoscondiabetes i.dificultadpagando baseline_thirdSC || numerodepaciente_e_i:


mi estimate, cmdok: meologit fourthSC i.time edad i.etnicidad i.genero anosdeeducacion anoscondiabetes i.dificultadpagando baseline_fourthSC || numerodepaciente_e_i:


mi estimate, cmdok: meologit sixthSC i.time edad i.etnicidad i.genero anosdeeducacion anoscondiabetes i.dificultadpagando baseline_sixthSC || numerodepaciente_e_i:



